#!/bin/bash

src=/data/test/blog.domain_config.json
des=/data/test/.env

URL=`grep app_url ${src} |sed -r 's/.*"(.+)".*/\1/'`
HOST=`grep db_host ${src} |sed -r 's/.*"(.+)".*/\1/'`
DATABASE=`grep db_name ${src} |sed -r 's/.*"(.+)".*/\1/'`
PORT=`grep db_port ${src} |sed -r 's/.*"(.+)".*/\1/'`
USERNAME=`grep db_username ${src} |sed -r 's/.*"(.+)".*/\1/'`
PASSWORD=`grep db_password ${src} |sed -r 's/.*"(.+)".*/\1/'`
ENV=`grep env ${src} |sed -r 's/.*"(.+)".*/\1/'`

sed -i "s!^\(APP_URL=\).*!\1$URL!" $des
sed -i "s/^\(DB_HOST=\).*/\1$HOST/" $des
sed -i "s/^\(DB_DATABASE=\).*/\1$DATABASE/" $des
sed -i "s/^\(DB_PORT=\).*/\1$PORT/" $des
sed -i "s/^\(DB_USERNAME=\).*/\1$USERNAME/" $des
sed -i "s/^\(DB_PASSWORD=\).*/\1$PASSWORD/" $des
sed -i "s/^\(APP_ENV=\).*/\1$ENV/" $des
